package models;

import java.util.ArrayList;
import java.util.HashMap;

public class ModelNode {
	// type, maybe represent as strings
	// label, represent as strings
	// attribute, where an attribute always is a combination of a type and a
	// label.
	// other nodes, to represent a tree
	// id, to find the correct node in the tree
	private int id = 0;

	// The HashMap that holds the data for the model
	private HashMap<String, String> data = new HashMap<String, String>();

	// children, this will be the immediate children in other words not
	// grandchildren etc.
	private ArrayList<ModelNode> children = new ArrayList<ModelNode>();
	// siblings
	private ArrayList<ModelNode> siblings = new ArrayList<ModelNode>();

	public ModelNode() {
	}

	public ModelNode(int id) {
		this.id = id;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public ArrayList<ModelNode> getChildren() {
		return children;
	}

	public void setChildren(ArrayList<ModelNode> children) {
		this.children = children;
	}

	public ArrayList<ModelNode> getSiblings() {
		return siblings;
	}

	public void setSiblings(ArrayList<ModelNode> siblings) {
		this.siblings = siblings;
	}

	public void addChild(ModelNode node) {
		// if children != empty add the node as sibling to all existing nodes
		// and
		// add those nodes as siblings to this node
		for (ModelNode child : children) {
			child.addSibling(node);
			node.addSibling(child);
		}
		children.add(node);
	}

	private void addSibling(ModelNode node) {
		this.siblings.add(node);
	}

	public HashMap<String, String> getData() {
		return data;
	}

	public void setData(HashMap<String, String> data) {
		this.data = data;
	}

	public void addData(String key, String value) {
		try {
			this.data.put(key, value);
		} catch (Exception ex) {
		}
	}

}
